package com.autumn.cloud.demo.provider.controllers.order;

import com.autumn.cloud.demo.common.constants.DemoServiceProviderUrlConstants;
import com.autumn.cloud.demo.common.model.OrderInfo;
import com.autumn.exception.UserFriendlyException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Random;

/**
 * <p>
 * </p>
 *
 * @description TODO
 * @author: 老码农
 * @create: 2020-12-11 16:58
 **/
@RestController
@Slf4j
public class OrderController {

    private final Random random = new Random();

    /**
     * 订单信息
     *
     * @return
     */
    @GetMapping(path = DemoServiceProviderUrlConstants.ORDER_INFO_URL)
    public OrderInfo orderInfo() {
        int i = this.random.nextInt(10);
        if (i % 2 == 0) {
            throw new UserFriendlyException("原始服务器随机产生的异常。");
        }
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setOrderTime(LocalDateTime.now());
        orderInfo.setOrderNo("0012522555");
        orderInfo.setTitle("话费充值");
        log.info("订单信息请求--原始服务器");
        return orderInfo;
    }
}
